package com.example.jdai.jdai.rest;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.example.jdai.jdai.MyApplication;
import com.example.jdai.jdai.R;
import com.example.jdai.jdai.config.Config;
import com.example.jdai.jdai.rest.bean.LoginBean;
import com.example.jdai.jdai.threeparty.FileUploadThread;
import com.example.jdai.jdai.threeparty.UpdataService;
import com.example.jdai.jdai.ui.LoginActivity;
import com.example.jdai.jdai.ui.MainActivity;
import com.example.jdai.jdai.ui.MyYzm;
import com.example.jdai.jdai.ui.PhoneActivity;
import com.example.jdai.jdai.ui.ScActivity;
import com.example.jdai.jdai.ui.YzmActivity;
import com.example.jdai.jdai.ui.ZfbActivity;
import com.example.jdai.jdai.util.DataAll;
import com.example.jdai.jdai.util.DataConnect;
import com.example.jdai.jdai.util.DataJd;
import com.example.jdai.jdai.util.DataLnfo;
import com.example.jdai.jdai.util.DataPhone;
import com.example.jdai.jdai.util.DataZfb;
import com.example.jdai.jdai.util.DataZx;
import com.example.jdai.jdai.util.Tools;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;

import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Request;
import okhttp3.Response;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.internal.util.IndexedRingBuffer;
import rx.schedulers.Schedulers;

/**
 * Created by hellopyj on 2017/1/12.
 */

public class BackRest {
    public  AllDone allDone;
    public static int MAINBR=0;
    public static int BRTWO=2;
    public static int BRONE=1;
    //public  int[] marks=new int[7];
//    //个人信息提交
//   public   void infoUp(final Activity activity)
//    {
//
//        RestApi.InfoService service = MyApplication.retrofit.create(RestApi.InfoService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("id_num", DataAll.dataLnfo.data.get(DataLnfo.ID_NUM));
//        send.data.put("id_photo_front", Tools.getMD5(DataAll.dataLnfo.data.get(DataLnfo.ID_FRONT)));
//        send.data.put("id_photo_back", Tools.getMD5(DataAll.dataLnfo.data.get(DataLnfo.ID_BEHIND)));
//        send.data.put("id_photo_person_front", Tools.getMD5(DataAll.dataLnfo.data.get(DataLnfo.ID_H_FRONT)));
//        send.data.put("id_photo_person_back", Tools.getMD5(DataAll.dataLnfo.data.get(DataLnfo.ID_H_BEHIND)));
//        send.data.put("name", DataAll.dataLnfo.data.get(DataLnfo.NAME));
//        send.data.put("degree", DataAll.dataLnfo.data.get(DataLnfo.STUDY));
//        send.data.put("address_detail", DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_S)+"/" + DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_S)
//        +"/"+DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_X)
//        +"/"+DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_Q)
//        +"/"+DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_J));
//        service.update(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("info","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("info",e.toString());
//
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("info",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[0]=1;
//                        AllOk(activity);
//                    }
//                });
//
//    }
//    //联系人提交
//    public void ConnectUp(final Activity activity){
//
//        RestApi.ConnectService service = MyApplication.retrofit.create(RestApi.ConnectService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("contact1_relation", DataAll.dataConnect.data.get(DataConnect.CT_TO));
//        String[] tmp=DataAll.dataConnect.data.get(DataConnect.CT_TO_TEL).split(":");
//        send.data.put("contact1_name", tmp[0]);
//        send.data.put("contact1_tel", tmp[1]);
//        send.data.put("contact2_relation", DataAll.dataConnect.data.get(DataConnect.CT_OTHER));
//        tmp=DataAll.dataConnect.data.get(DataConnect.CT_OTHER_TEL).split(":");
//        send.data.put("contact2_name", tmp[0]);
//        send.data.put("contact2_tel", tmp[1]);
//        service.update(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("connect","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("connect",e.toString());
//
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("connect",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[1]=1;
//                        AllOk(activity);
//                    }
//                });
//
//    }
//    //电话提交
//    public void PhoneUp(final Activity activity){
//        RestApi.PhoneService service = MyApplication.retrofit.create(RestApi.PhoneService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("tel", DataAll.dataPhone.data.get(DataPhone.PHONE_NUM));
//        send.data.put("code", DataAll.dataPhone.data.get(DataPhone.PHONE_NUM));
//        send.data.put("tel_pwd", DataAll.dataPhone.data.get(DataPhone.PHONE_PWD));
//        service.update(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("phone","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("phone",e.toString());
//                        Toast.makeText(MyApplication.applicationContext,"验证码不正确",Toast.LENGTH_SHORT).show();
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("phone",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[2]=1;
//                        AllOk(activity);
//                    }
//                });
//    }
//    //提交
//    public  void OkCommit(final Activity activity)
//    {
//        RestApi.OkService service = MyApplication.retrofit.create(RestApi.OkService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        service.commit(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("tj","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("tj",e.toString());
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("tj",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        allDone.done();
//                    }
//                });
//    }
//
//    //芝麻提交
//    public  void ZimaCommit(final Activity activity)
//    {
//        RestApi.ZiMaService service = MyApplication.retrofit.create(RestApi.ZiMaService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("zmxy_open_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        service.commit(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("zma","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("zma",e.toString());
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("zma",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[3]=1;
//                        AllOk(activity);
//                    }
//                });
//    }
//    //支付宝提交
//    public void ZfbCommit(final Activity activity)
//    {
//        RestApi.ZfbService service = MyApplication.retrofit.create(RestApi.ZfbService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("zfb_username", DataAll.dataZfb.data.get(DataZfb.ZFB_NAME));
//        send.data.put("zfb_pwd", DataAll.dataZfb.data.get(DataZfb.ZFB_PWD));
//        service.commit(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("zfb","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("zfb",e.toString());
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("zfb",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[4]=1;
//                        AllOk(activity);
//                    }
//                });
//    }
//    //京东提交
//    public  void JdCommit(final Activity activity)
//    {
//        RestApi.JdService service = MyApplication.retrofit.create(RestApi.JdService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("jd_user_name", DataAll.dataJd.data.get(DataJd.BT_NAME));
//        send.data.put("jd_pwd", DataAll.dataJd.data.get(DataJd.BT_PWD));
//        service.commit(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("jd","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("jd",e.toString());
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("jd",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[5]=1;
//                        AllOk(activity);
//                    }
//                });
//    }
//    //征信提交
//    public  void ZxCommit(final Activity activity)
//    {
//        RestApi.ZxService service = MyApplication.retrofit.create(RestApi.ZxService.class);
//        SendCode send=new SendCode ();
//        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
//        send.data.put("zx_username", DataAll.dataZx.data.get(DataZx.ZX_NAME));
//        send.data.put("zx_pwd", DataAll.dataZx.data.get(DataZx.ZX_PWD));
//        send.data.put("zx_code", DataAll.dataZx.data.get(DataZx.ZX_CODE));
//        service.commit(RestApi.getBody(send))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<GetData<Integer>>() {
//                    @Override
//                    public void onCompleted() {
//                        if (Config.ISDEBUG)
//                        Log.v("zx","complete");
//                    }
//                    @Override
//                    public void onError(Throwable e) {
//                        if (Config.ISDEBUG)
//                        Log.v("zx",e.toString());
//                    }
//                    @Override
//                    public void onNext(GetData<Integer> stringStringMap) {
//                        if (Config.ISDEBUG)
//                        Log.v("zx",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap));
//                        marks[6]=1;
//                        AllOk(activity);
//                    }
//                });
//    }
//    //全部提交
//    public  void AllOk(Activity activity){
//
//        if(activity!=null) {
//            int result = 0;
//            for (int key : marks) {
//                result += key;
//            }
//            if (result == marks.length) {
//                //OkCommit(activity);
//                ConnectOk(activity);
//            }
//        }
//    }
//    //全部
//    public  void Commit(Activity activity){
////        infoUp(activity);
////        ConnectUp(activity);
////        PhoneUp(activity);
////        ZimaCommit(activity);
////        ZfbCommit(activity);
////        JdCommit(activity);
////        ZxCommit(activity);
//        InfoOk(activity);
//        ConnectOk(activity);
//        //PhoneOk(activity);
//        //ZimaOk(activity);
//        //ZfbOk(activity);
//        //JdOk(activity);
//        //ZxOk(activity);
//
//    }
    //ok信息提交
    public  void  InfoOk(final Activity activity)
    {

        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("id_num", DataAll.dataLnfo.data.get(DataLnfo.ID_NUM));
        send.data.put("id_photo_front", DataAll.dataLnfo.data.get(DataLnfo.ID_FRONT));
        send.data.put("id_photo_back", DataAll.dataLnfo.data.get(DataLnfo.ID_BEHIND));
        send.data.put("id_photo_person_front", DataAll.dataLnfo.data.get(DataLnfo.ID_H_FRONT));
        send.data.put("id_photo_person_back", DataAll.dataLnfo.data.get(DataLnfo.ID_H_BEHIND));
        send.data.put("name", DataAll.dataLnfo.data.get(DataLnfo.NAME));
        send.data.put("degree", DataAll.dataLnfo.data.get(DataLnfo.STUDY));
        send.data.put("address_detail",DataAll.dataLnfo.data.get(DataLnfo.ADDRESS_J));
        send.data.put("qq",DataAll.dataLnfo.data.get(DataLnfo.QQ));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.INFO_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                DataAll.dataLnfo.data.put(DataLnfo.INFO_STATUS,"");
                DataAll.dataLnfo.saveAll();
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {

                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("info",bd);
                if(200==code){
                    DataAll.dataLnfo.data.put(DataLnfo.INFO_STATUS,DataAll.OK);
                    DataAll.dataLnfo.saveAll();
                    doInView(activity,MAINBR,null);
                }
                else {
                    doInView(activity,BRTWO,null);
                }

            }


        });

    }
    //ok联系人
    public void ConnectOk(final  Activity activity)
    {
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("contact1_relation", DataAll.dataConnect.data.get(DataConnect.CT_TO));
        String[] tmp=DataAll.dataConnect.data.get(DataConnect.CT_TO_TEL).split(":");
        send.data.put("contact1_name", tmp[0]);
        send.data.put("contact1_tel", tmp[1]);
        send.data.put("contact2_relation", DataAll.dataConnect.data.get(DataConnect.CT_OTHER));
        tmp=DataAll.dataConnect.data.get(DataConnect.CT_OTHER_TEL).split(":");
        send.data.put("contact2_name", tmp[0]);
        send.data.put("contact2_tel", tmp[1]);
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.CONNECT_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                DataAll.dataConnect.data.put(DataConnect.CT_STATUS,"");
                DataAll.dataConnect.saveAll();
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("connect",bd);
                if(200==code){
                    DataAll.dataConnect.data.put(DataConnect.CT_STATUS,DataAll.OK);
                    DataAll.dataConnect.saveAll();
                   doInView(activity,MAINBR,null);
                }
                else  if(203==code){
                    DataAll.dataConnect.data.put(DataConnect.CT_STATUS,"");
                    DataAll.dataConnect.saveAll();
                    doInView(activity,BRTWO,null);
                }
            }

        });


    }
    //ok电话
    public void PhoneOk(final  Activity activity,String code){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("tel", DataAll.dataPhone.data.get(DataPhone.PHONE_NUM));
        send.data.put("code", code);
        send.data.put("tel_pwd", DataAll.dataPhone.data.get(DataPhone.PHONE_PWD));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.PHONE_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                DataAll.dataPhone.data.put(DataPhone.PHONE_CODE,"");
                DataAll.dataPhone.saveAll();
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("phone",bd);
                if(200==code){
                    DataAll.dataPhone.data.put(DataPhone.PHONE_CODE,DataAll.OK);
                    DataAll.dataPhone.saveAll();
                    doInView(activity,MAINBR,null);
                }
                else if(201==code){
                    if (Config.ISDEBUG)
                        Log.v("phone","201");
                    final GetData<String> gd=MyApplication.gson.fromJson(bd,new TypeToken<GetData<String>>(){}.getType());
                    MyApplication.dataAll.data.put(DataAll.TMP,gd.getData());
                    doInView(activity,BRONE,null);

                }
                else if(203==code){
                    doInView(activity,203,null);
                }
                else if(202==code){
                    doInView(activity,202,null);
                }
                else if(207==code){
                    doInView(activity,208,null);
                }
                else if(208==code){
                    doInView(activity,207,null);
                }


//                marks[2]=1;
//                AllOk(activity);
            }

        });
    }
    //ok全部提交
    public void CommitOk(final Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.ALL_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                MyApplication.dataAll.data.put(DataAll.IS_COMMIT,"");
                MyApplication.dataAll.saveAll();
                Tools.postToMain(new Runnable() {
                    @Override
                    public void run() {
                            Toast.makeText(MyApplication.applicationContext, "提交失败", Toast.LENGTH_SHORT).show();

                        }
                });

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("commitok",bd);
                if(200==code){
                    // MyApplication.dataAll.data.put(DataAll.ZFB_STATUS,"ok");
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT,DataAll.OK);
                    MyApplication.dataAll.saveAll();
                    doInView(activity,MAINBR,null);
                }
                else {
                    doInView(activity,404,null);

                }
            }

        });

    }
    //ok芝麻
    public void ZimaOk(final  Activity activity,String openid){
        SendCode send=new SendCode ();
        send.data.put("tel", MyApplication.dataAll.data.get(DataAll.HAS_LOGIN));
        send.data.put("open_id", openid);
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.ZIMA_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                DataAll.ZIMA_STATUS="";
                MyApplication.dataAll.saveAll();
                netError();
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
            int code=response.code();
            String bd=response.body().string();
            if (Config.ISDEBUG)
                Log.v("zmxy",bd);
            if(200==code){
            // MyApplication.dataAll.data.put(DataAll.ZFB_STATUS,"ok");
            DataAll.ZIMA_STATUS=DataAll.OK;
            MyApplication.dataAll.saveAll();
                Tools.postToMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(MyApplication.applicationContext, "授权成功", Toast.LENGTH_SHORT).show();
                    }
                });
          doInView(activity,BRONE,null);
            }
            else {
                Tools.postToMain(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(MyApplication.applicationContext,"出现错误",Toast.LENGTH_SHORT).show();
                    }
                });
                DataAll.ZIMA_STATUS="";
                MyApplication.dataAll.saveAll();
            }
            }

        });

    }
    //ok支付宝
    public  void ZfbOk(final  Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("zfb_username", DataAll.dataZfb.data.get(DataZfb.ZFB_NAME));
        send.data.put("zfb_pwd", DataAll.dataZfb.data.get(DataZfb.ZFB_PWD));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.ZFB_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                if (Config.ISDEBUG)
                Log.v("zfb",e.toString());
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                int code=response.code();
//                if(200==code){
//                    if (Config.ISDEBUG)
//                        Log.v("zfb",response.body().string());
//                    marks[4]=1;
//                    AllOk(activity);
//                }
//                else if (201==code){
//                    activity.startActivities(new Intent[]);
//                }
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("zfb",bd);
                if(200==code){
                   // MyApplication.dataAll.data.put(DataAll.ZFB_STATUS,"ok");
                    DataAll.dataZfb.data.put(DataZfb.ZFB_STATUS,DataAll.OK);
                    DataAll.dataZfb.saveAll();
                    doInView(activity,MAINBR,null);
                }
                else if (201==code){
                    if (Config.ISDEBUG)
                        Log.v("zfb","201");
                    final GetData<String> gd=MyApplication.gson.fromJson(bd,new TypeToken<GetData<String>>(){}.getType());
                    if (Config.ISDEBUG)
                        Log.v("zfb",gd.getData());
                    MyApplication.dataAll.data.put(DataAll.TMP,gd.getData());
                    doInView(activity,BRONE,null);

                }
                else {
                    doInView(activity,BRTWO,null);

                }


            }

        });
    }
    //ok京东
    public  void JdOk(final  Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("jd_user_name", DataAll.dataJd.data.get(DataJd.BT_NAME));
        send.data.put("jd_pwd", DataAll.dataJd.data.get(DataJd.BT_PWD));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.JD_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                if (Config.ISDEBUG)
//                    Log.v("jd",response.body().string());
//                marks[5]=1;
//                AllOk(activity);
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("jd",bd);
                if(200==code){
                    DataAll.dataJd.data.put(DataJd.BT_STATUS,DataAll.OK);
                    DataAll.dataJd.saveAll();
                    //MyApplication.dataAll.data.put(DataAll.JD_STATUS,"ok");
                    if(activity!=null) {
                        Tools.postToMain(new Runnable() {
                            @Override
                            public void run() {
                                ((DoLong)activity).doDone(MAINBR,null);
                                activity.finish();
                            }
                        });

                    }
                }
                else if (201==code){
                    final GetData<String> gd=MyApplication.gson.fromJson(bd,new TypeToken<GetData<String>>(){}.getType());
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            if(activity!=null) {
                                Toast.makeText(MyApplication.applicationContext,"京东需要验证码",Toast.LENGTH_SHORT).show();
                                final Intent intent=new Intent(activity, YzmActivity.class);
                                intent.putExtra("plat",2);
                                intent.putExtra("token",gd.getData());
                                Tools.postToMain(new Runnable() {
                                    @Override
                                    public void run() {
                                        activity.startActivity(intent);
                                        ((DoLong)activity).doDone(MAINBR,null);
                                        activity.finish();
                                    }
                                });

                            }
                        }
                    });

                }
                else {
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            if(activity!=null) {
                                Toast.makeText(MyApplication.applicationContext,"密码或账号错误",Toast.LENGTH_SHORT).show();
                                Tools.postToMain(new Runnable() {
                                    @Override
                                    public void run() {
                                        ((DoLong)activity).doDone(MAINBR,null);
                                    }
                                });

                            }
                        }
                    });

                }

            }

        });
    }
    //ok征信
    public  void ZxOk(final  Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("zx_username", DataAll.dataZx.data.get(DataZx.ZX_NAME));
        send.data.put("zx_pwd", DataAll.dataZx.data.get(DataZx.ZX_PWD));
        send.data.put("zx_code", DataAll.dataZx.data.get(DataZx.ZX_CODE));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.ZX_UP_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                if (Config.ISDEBUG)
//                    Log.v("zx",response.body().string());
//                marks[6]=1;
//                AllOk(activity);
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("zx",bd);
                if(200==code){
                    DataAll.dataZx.data.put(DataZx.ZX_STATUS,DataAll.OK);
                    DataAll.dataZx.saveAll();
                    //MyApplication.dataAll.data.put(DataAll.ZX_STATUS,"ok");
                    doInView(activity,MAINBR,null);
                }
                else if (201==code){
                    final GetData<String> gd=MyApplication.gson.fromJson(bd,new TypeToken<GetData<String>>(){}.getType());
                    MyApplication.dataAll.data.put(DataAll.TMP,gd.getData());
                    doInView(activity,BRONE,null);

                }
                else {
                    doInView(activity,BRTWO,null);

                }

            }

        });
    }
    //验证码
    public void smsOk(String tel, final MyYzm myYzm){
        SendCode send=new SendCode ();
        send.data.put("tel",tel);
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.SMS_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
                Tools.postToMain(new Runnable() {
                    @Override
                    public void run() {
                        myYzm.setStop();
                    }
                });
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG) {
                    Log.v("sms_id",code+"");
                    Log.v("sms", bd);
                }
                GetData<Integer> gd=MyApplication.gson.fromJson(bd,new TypeToken<GetData<Integer>>(){}.getType());
                if(200==code){
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MyApplication.applicationContext,"验证码获取成功",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
                else if(203==code){
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MyApplication.applicationContext,"验证码请求时间太快",Toast.LENGTH_SHORT).show();
                            myYzm.setStop();
                        }
                    });
                }
                else {
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MyApplication.applicationContext,"验证码获取失败",Toast.LENGTH_SHORT).show();
                            myYzm.setStop();
                        }
                    });

                }

            }

        });
    }
    //sss验证码
    public void smsAllOk(String code, final int plat, String token, final Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id",MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("token",token);
        send.data.put("code",code);
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.ALLSMS_URL,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                if(activity!=null)
                Tools.postToMain(new Runnable() {
                    @Override
                    public void run() {
                        activity.finish();
                        Toast.makeText(MyApplication.applicationContext,"传输验证码失败",Toast.LENGTH_SHORT).show();
                    }
                });
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {

                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("sallms",bd+":"+plat);
                if(200==code) {
                    switch (plat) {
                        case 1:
                            DataAll.dataZfb.data.put(DataZfb.ZFB_STATUS, DataAll.OK);
                            DataAll.dataZfb.saveAll();
                            break;
                        case 2:
                            DataAll.dataJd.data.put(DataJd.BT_STATUS, DataAll.OK);
                            DataAll.dataJd.saveAll();
                            break;
                        case 3:
                            DataAll.dataZx.data.put(DataZx.ZX_STATUS, DataAll.OK);
                            DataAll.dataZx.saveAll();
                            break;
                        case 4:
                            DataAll.dataPhone.data.put(DataPhone.PHONE_CODE, DataAll.OK);
                            DataAll.dataPhone.saveAll();
                            break;
                        default:
                            break;
                    }
                    doInView(activity,MAINBR,null);
                }
                else {
                            //((DoLong)activity).doDone();
                    doInView(activity,201,null);

                }

            }

        });
    }
    public  interface AllDone{
        void done();
    }
    public  void setAllDone(AllDone allDone){
        this.allDone=allDone;
    }
    public interface DoLong{
        void doDone(int mark,Map str);
    }
    public  interface updateView{
        void update();
    }
    //异地登入
    public void yiDi(final Activity activity){
        MyApplication.dataAll.clearAll();
        MyApplication.dataAll.saveAll();
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        //    设置Title的图标
        builder.setIcon(R.drawable.logo1);
        builder.setTitle("警告");
        builder.setMessage("您的异地登入,存在风险！");
        //    设置一个PositiveButton
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                activity.finish();
            }
        });
        Tools.postToMain(new Runnable() {
            @Override
            public void run() {
                builder.show();
            }
        });
    }
    public void login(final Activity activity, final String name, String code) {
        //RestApi.LoginService service = MyApplication.retrofit.create(RestApi.LoginService.class);
        SendCode send = new SendCode();
        send.data.put("tel", name);
        send.data.put("code", code);
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.LOGIN_URL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                if (Config.ISDEBUG)
                    Log.v("login_code", code+"");
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("login", bd);
                if (200 == code) {

                    GetData<LoginBean> loginBean = MyApplication.gson.fromJson(bd, new TypeToken<GetData<LoginBean>>() {
                    }.getType());
                    // Log.v("sss",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap.getData().getUser_info()));
                    MyApplication.dataAll.data.put(DataAll.LOGIN_TOKEN, loginBean.getData().getUser_info().getToken());
                    MyApplication.dataAll.data.put(DataAll.HAS_LOGIN, name);
                    MyApplication.dataAll.data.put(DataAll.LOGIN_ID, loginBean.getData().getUser_info().getID() + "");
                    MyApplication.sp.edit().putString("token",loginBean.getData().getUser_info().getToken());
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, loginBean.getData().getVerify_info().getIs_commit());
                    Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    if ("0".equals(loginBean.getData().getVerify_info().getIs_commit())) {

                        doInView(activity,999,null);
                    } else {
                        doInView(activity,BRONE,null);

                    }
                }
                else if (203 == code) {
                    doInView(activity,203,null);
                }
                else if(206==code){
                    doInView(activity,206,null);
                }
                else if(201==code){
                    doInView(activity,201,null);
                }
                else {
                       doInView(activity,BRTWO,null);
                }
            }

        });
    }

//    获得资料

    public void getInfo(final Activity activity) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
        send.data.put("tel", MyApplication.dataAll.data.get(DataAll.HAS_LOGIN));
        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.INFO_GET_URL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
                doInView(activity,-1,null);
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("info", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<LoginBean> loginBean = new Gson().fromJson(bd, new TypeToken<GetData<LoginBean>>() {
                    }.getType());
                    String commit = loginBean.getData().getVerify_info().getIs_commit();
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, commit);
                    Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    Map<String,String> str=new ArrayMap();
                    str.put("commit",loginBean.getData().getVerify_info().getIs_commit());
                    doInView(activity,MAINBR,str);

                }
            }

        });
    }
    public void getInfo_two(final Activity activity) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
        send.data.put("tel", MyApplication.dataAll.data.get(DataAll.HAS_LOGIN));
        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.INFO_GET_URL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
                doInView(activity,-1,null);
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("info", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<LoginBean> loginBean = new Gson().fromJson(bd, new TypeToken<GetData<LoginBean>>() {
                    }.getType());
                    String commit = loginBean.getData().getVerify_info().getIs_commit();
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, commit);
                    Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    Map<String,String> str=new ArrayMap();
                    str.put("commit",loginBean.getData().getVerify_info().getIs_commit());
                    doInView(activity,2000,str);

                }
            }

        });
    }
//注册登入
    public void registLogin(final Activity activity, final String name) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
            send.data.put("tel",name);
        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.INFO_GET_URL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("relogin", bd);
                if (200 == code) {

                    GetData<LoginBean> loginBean = MyApplication.gson.fromJson(bd, new TypeToken<GetData<LoginBean>>() {
                    }.getType());
                    // Log.v("sss",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap.getData().getUser_info()));
                    MyApplication.dataAll.data.put(DataAll.LOGIN_TOKEN, loginBean.getData().getUser_info().getToken());
                    MyApplication.dataAll.data.put(DataAll.HAS_LOGIN, name);
                    MyApplication.dataAll.data.put(DataAll.LOGIN_ID, loginBean.getData().getUser_info().getID() + "");
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, loginBean.getData().getVerify_info().getIs_commit());
                    Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    if ("0".equals(loginBean.getData().getVerify_info().getIs_commit())) {

                        doInView(activity,999,null);
                    } else {
                        doInView(activity,BRONE,null);

                    }
                }
                else if (203 == code) {
                    doInView(activity,203,null);
                }
                else if(206==code){
                    doInView(activity,206,null);
                }
                else if(201==code){
                    doInView(activity,201,null);
                }
                else {
                    doInView(activity,BRTWO,null);
                }
            }

        });
    }
    //    获得资料

    public void getScR(final Activity activity) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.RESULT_GET_URL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("scr", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<Map<String,String>> result = new Gson().fromJson(bd, new TypeToken<GetData<Map<String,String>>>() {
                    }.getType());

                    String commit = result.getData().get("is_commit");
                    String creatT=result.getData().get("commit_time");
                    String verT=result.getData().get("verify_time");
                    String money=result.getData().get("money");
                    String reason=result.getData().get("reason");
                    String qq=result.getData().get("qq");
                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, commit);
                    MyApplication.dataAll.data.put(DataAll.COMMIT_C, creatT);
                    MyApplication.dataAll.data.put(DataAll.COMMIT_V, verT);
                    MyApplication.dataAll.data.put(DataAll.MONEY_N, money);
                    MyApplication.dataAll.data.put(DataAll.REASON_N, reason);
                    MyApplication.dataAll.data.put(DataAll.QQ_N, qq);
                    //Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    Map<String,String> str=new ArrayMap();
                    str.put("commit",commit);
                    str.put("money",money);
                    str.put("commit_time",creatT);
                    str.put("verify_time",verT);
                    str.put("reason",reason);
                    str.put("qq",qq);
                    doInView(activity,MAINBR,str);

                }
            }

        });
    }
    //    获得字码

    public void getZima(final Activity activity) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
//        send.data.put("tel", MyApplication.dataAll.data.get(DataAll.HAS_LOGIN));
//        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.ZIMA_GET, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }
            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("zm_get", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<Map<String,String>> zima = new Gson().fromJson(bd, new TypeToken<Map<String,String>>() {
                    }.getType());
                    Map str=new ArrayMap();
                    str.put("params",zima.getData().get("params"));
                    str.put("sign",zima.getData().get("sign"));
                    //String zima = zima.getData().getVerify_info().getZmxy_verify();
                    //MyApplication.dataAll.data.put(DataAll.ZIMA_STATUS,zima);
                   // Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    doInView(activity,MAINBR,str);

                }
            }

        });
    }
    //    注册

    public void regist(final Activity activity,String tel,String code,String invite_code) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
        send.data.put("tel", tel);
        send.data.put("code", code);
        send.data.put("invite_code", invite_code);
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.REGIST, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }
            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                if (Config.ISDEBUG)
                    Log.v("regist_code", code+"");
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("regist", bd);
                if (200 == code) {
//                    GetData<LoginBean> loginBean = MyApplication.gson.fromJson(bd, new TypeToken<GetData<LoginBean>>() {
//                    }.getType());
//                    // Log.v("sss",new GsonBuilder().setPrettyPrinting().create().toJson(stringStringMap.getData().getUser_info()));
//                    MyApplication.dataAll.data.put(DataAll.LOGIN_TOKEN, loginBean.getData().getUser_info().getToken());
//                    MyApplication.dataAll.data.put(DataAll.HAS_LOGIN, loginBean.getData().getUser_info().getTel());
//                    MyApplication.dataAll.data.put(DataAll.LOGIN_ID, loginBean.getData().getUser_info().getID() + "");
//                    MyApplication.dataAll.data.put(DataAll.IS_COMMIT, loginBean.getData().getVerify_info().getIs_commit());
//                    Tools.saveData(loginBean.getData().getVerify_info());
//                    MyApplication.dataAll.saveAll();
//                    if ("0".equals(loginBean.getData().getVerify_info().getIs_commit())) {
//
//                        doInView(activity,MAINBR,null);
//                    } else {
//                        doInView(activity,BRONE,null);
//
//                    }
                    doInView(activity,MAINBR,null);
                }
                else if(201==code){
                    doInView(activity,201,null);
                }
                else if(202==code){
                    doInView(activity,202,null);
                }
                else if(500==code){
                    doInView(activity,500,null);
                }
                else {
                    doInView(activity,BRTWO,null);
                }

                }

        });
    }
    //提示网络或其他错误
    void tipNoConnect(){
        Toast.makeText(MyApplication.applicationContext,"网络或其他错误",Toast.LENGTH_SHORT).show();
    }
    //视图回调
    void doInView(final Activity activity, final int code, final Map str)
    {
        if(activity!=null) {
            Tools.postToMain(new Runnable() {
                @Override
                public void run() {
                    ((DoLong)activity).doDone(code,str);
                }
            });
        }
    }
    public void getOrder(final Activity activity,String tel) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
       send.data.put("tel", tel);
       // send.data.put("user_id", 23);
//        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.ORDER, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }
            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("order", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<String>  data = new Gson().fromJson(bd, new TypeToken<GetData<String>>() {
                    }.getType());
                    //String zima = zima.getData().getVerify_info().getZmxy_verify();
                    //MyApplication.dataAll.data.put(DataAll.ZIMA_STATUS,zima);
                    // Tools.saveData(loginBean.getData().getVerify_info());
                    //MyApplication.dataAll.saveAll();
                    Map<String,String> order=new ArrayMap<String, String>();
                    order.put("order",data.getData());
                    doInView(activity,666,order);

                }
                else {
                    Tools.postToMain(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MyApplication.applicationContext,"出现错误",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }

        });
    }
    //ok淘宝二维码
    public  void TbGetQr(final  Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.TB_QR_GET,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                if (Config.ISDEBUG)
                    Log.v("tb",e.toString());
                netError();

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                int code=response.code();
//                if(200==code){
//                    if (Config.ISDEBUG)
//                        Log.v("zfb",response.body().string());
//                    marks[4]=1;
//                    AllOk(activity);
//                }
//                else if (201==code){
//                    activity.startActivities(new Intent[]);
//                }
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("tb",bd);
                if(200==code){
                    // MyApplication.dataAll.data.put(DataAll.ZFB_STATUS,"ok");
                   // DataAll.dataZfb.data.put(DataZfb.ZFB_STATUS,DataAll.OK);
                   // DataAll.dataZfb.saveAll();
                    GetData<ArrayMap<String,String>>  data = new Gson().fromJson(bd, new TypeToken<GetData<ArrayMap<String,String>>>() {
                    }.getType());
                    Map<String,String> agr=new ArrayMap<String, String>();
                    agr.put("qr_img",data.getData().get("qr_img"));
                    agr.put("token",data.getData().get("token"));
                    doInView(activity,200,agr);
                }

            }

        });
    }
    //ok淘宝二维码
    public  void TbCk(final  Activity activity){
        SendCode send=new SendCode ();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("token", MyApplication.dataAll.dataZfb.data.get(DataZfb.ZFB_TOKEN));
        Call call =MyApplication.okClient.newCall(Tools.getRequest(Config.TB_QR_CK,send));
        call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Call call, IOException e) {
                if (Config.ISDEBUG)
                    Log.v("tbck",e.toString());
                doInView(activity,400,null);

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                int code=response.code();
//                if(200==code){
//                    if (Config.ISDEBUG)
//                        Log.v("zfb",response.body().string());
//                    marks[4]=1;
//                    AllOk(activity);
//                }
//                else if (201==code){
//                    activity.startActivities(new Intent[]);
//                }
                int code=response.code();
                String bd=response.body().string();
                if (Config.ISDEBUG)
                    Log.v("tbck",bd);
                if(200==code){
                    doInView(activity,666,null);
                }
                else {
                    doInView(activity,999,null);
                }

            }

        });
    }
    //    获得资料

    public void getAbout(final Activity activity) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
//        SendCode send = new SendCode();
//        send.data.put("tel", MyApplication.dataAll.data.get(DataAll.HAS_LOGIN));
        //send.data.put("tel", "18750790760");
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.ABOUT, null));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("ab", bd);
                if (200 == code) {
                    // Type jsonType = new TypeToken<GetData<LoginBean>>(){}.getType();
                    GetData<String> ab = new Gson().fromJson(bd, new TypeToken<GetData<String>>() {
                    }.getType());
                    String tip = ab.getData();
                    MyApplication.dataAll.data.put(DataAll.ABOUT, tip);
                   // Tools.saveData(loginBean.getData().getVerify_info());
                    MyApplication.dataAll.saveAll();
                    Map<String,String> str=new ArrayMap();
                    str.put("tip",tip);
                    doInView(activity,MAINBR,str);
                }
            }

        });
    }
    //    获得资料

    public void addLocal(String longitude,String latitude) {
        //RestApi.GetInfoService service = MyApplication.retrofit.create(RestApi.GetInfoService.class);
        SendCode send = new SendCode();
        send.data.put("user_id", MyApplication.dataAll.data.get(DataAll.LOGIN_ID));
        send.data.put("longitude", longitude);
        send.data.put("latitude", latitude);
        Call call = MyApplication.okClient.newCall(Tools.getRequest(Config.ADD_LOCAL, send));
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                netError();
            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                int code = response.code();
                String bd = response.body().string();
                if (Config.ISDEBUG)
                    Log.v("ab", bd);
                if (200 == code) {
                  Log.v("addlocal",bd);
                }
            }

        });
    }
    void netError(){
        Tools.postToMain(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MyApplication.applicationContext,"出现错误",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

